var timer = setInterval(CheckState,2000);
var timeout = setTimeout(TimeoutOccured,20000);
var ajaxStarted= false;

function CheckState()
{
  if(!ajaxStarted)
  {
    ajaxStarted=true;
   $.post("ajax/checkState.php").done(function(data)
   {
     if(data==="true")
     {
       (document.getElementById("progresspic")).innerHTML='<img src="../design/pictures/tick.png" width="16px" alt="Fertig"/>';
       clearInterval(timer);
       clearTimeout(timeout);
     }
     else if(data==="error")
     {
       (document.getElementById("progresspic")).innerHTML='<img src="../design/pictures/error.png" width="16px" alt="Error"/>';
       clearInterval(timer);
       clearTimeout(timeout);
     }
     
     ajaxStarted=false;
   });  
  }
}

function TimeoutOccured()
{
  (document.getElementById("progresspic")).innerHTML='<img src="../design/pictures/error.png" width="16px" alt="Error"/>';
  clearInterval(timer);
  clearTimeout(timeout);
}
